<template>
  <div>
    <!-- 添加或修改资产清单表对话框 -->
    <el-dialog v-model="openFlag" :title="title" width="600" append-to-body>

      <vxe-table style="height: 100%;flex-grow: 1;"
                 border="full"
                 ref="tableRef"
                 :column-config="{resizable: true}"
                 :data="list">
        <vxe-column field="userName" title="名称"></vxe-column>
        <vxe-column field="nickName" title="昵称"></vxe-column>
        <vxe-column field="phonenumber" title="电话"></vxe-column>
        <vxe-column field="email" title="邮箱"></vxe-column>
        <vxe-column field="remark" title="备注"></vxe-column>

      </vxe-table>

      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="close">取 消</el-button>
      </div>
    </el-dialog>


  </div>
</template>

<script setup>

import api from "./api.js";

const { proxy } = getCurrentInstance();

const emit = defineEmits(['sub'])

const openFlag = ref(false);
const isEdit = ref(false);
const title = ref();

const form = ref();

const list = ref([]);

function getList(roleId) {
  return api.listUser(roleId)
}

function open(row) {
  const roleId = row.roleId;
  title.value = `角色：【${row.roleName}】的用户`;
  openFlag.value = true;
  getList(roleId).then(response => {
    list.value = response;
  })
}

function close() {
  openFlag.value = false;
}

function submitForm() {
  form.value.validate(valid => {
    if (valid) {
      const params = { ...formData };
      if (isEdit.value) {

        api.update(params).then(response => {
          proxy.$modal.msgSuccess("修改成功");
          close();
          emit("sub");
        });
      } else {
        api.add(params).then(response => {
          proxy.$modal.msgSuccess("新增成功");
          close();
          emit("sub");
        })
      }

    }
  });
}

defineExpose({
  open
})




</script>

